/*触发链接通用*/
layui.use(['jquery', 'form'],
function() {
    var jq = layui.jquery;
    jq('.chufa115cms_t').click(function(){
    	var url = jq(this).attr('url');
    	var title = jq(this).attr('title');
    	var code = jq(this).attr('code');
        layer.confirm(title, function(index){
        loading = layer.load(2, {
          shade: [0.2,'#000']
        });
        jq.getJSON(url, function(data) {
          if(data.code == code){
             layer.close(loading);
            layer.msg(data.msg, {icon: 1, time: 1000}, function(){
              location.reload();
            });
          }else{
           layer.close(loading);
            layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
          }
        });
      });
    });
    jq('.chufa115cms').click(function() {
        /*链接地址*/
        var url = jq(this).attr('url');
        /*1是点赞2是收藏3就是刷新*/
        var res = jq(this).attr('res');
        /*成功返回一般就是200和1*/
        var code = jq(this).attr('code');
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        jq.getJSON(url,
        function(data) {
            if (data.code == code) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    anim: 2,
                    time: 1000
                },
                function() {
                    if (res == 1) {
                        zan = $(".dianzan").html();
                        $(".dianzan").html(zan + '+1');
                    }
                    if (res == 2) {
                        $(".shoucang").html("取消收藏");
                    }
                    if (res == 3) {
                        location.reload();
                    }
                });
            } else if (data.code == 2) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    $(".shoucang").html("收藏");
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                },
                function() {});
            }
        });
        return false;
    });
});
/*编辑器及提交*/
var editor;
var layedit;
layui.use(['layedit', 'form', 'upload'],
function() {
    var form = layui.form,
    upload = layui.upload,
    jq = layui.jquery,
    layedit = layui.layedit;
    layedit.set({
        uploadImage: {
            url: '/index.php/index_upimg_up.html',
            accept: 'image',
            acceptMime: 'image/*',
            exts: 'jpg|png|gif|bmp|jpeg',
            size: '10240'
        }
        , uploadVideo: {
            url: '/index.php/index_upimg_up.html',
            accept: 'video',
            acceptMime: 'video/*',
            exts: 'mp4|flv|avi|rm|rmvb',
            size: '20480'
        }
        , calldel: {
            url: '/index.php/index_upimg_up.html'
        }
        ,devmode: false
        , codeConfig: {
            hide: true
        ,default:
            'javascript' 
        }
        ,tool: [ 'code', '|', 'colorpicker', 'face', '|', 'left', 'center', 'right', '|', 'link', 'unlink', 'image_alt','fullScreen'],
        height: '100'
    });
    editor = layedit.build('content');
    form.verify({
        content: function(value) {
            return layedit.sync(editor);
        },
    });
    form.on('submit(cmsa)',
    function(data) {
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        var urls=jq('.forma form').attr('url');
        var param = data.field;
        jq.post(urls, param,
        function(data) {
            if (data.code == 1) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    location.reload();
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
        return false;
    });
  
    form.on('submit(cmsb)',
    function(data) {
        loading = layer.load(2, {
            shade: [0.2, '#000']
        });
        var urls=jq('.formb form').attr('url');
        var param = data.field;
        jq.post(urls, param,
        function(data) {
            if (data.code == 200) {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                },
                function() {
                    location.reload();
                });
            } else {
                layer.close(loading);
                layer.msg(data.msg, {
                    icon: 2,
                    anim: 6,
                    time: 1000
                });
            }
        });
        return false;
    });
})
/*多条件筛选*/
layui.use(['layer', 'jquery', 'form'],
    function() {
    var form = layui.form,
    laydate = layui.laydate,
    $form = $('#fenlei'),
    jq = layui.jquery;
    form.on('radio()',function(data) {
         $form.submit();
    });
    form.on('select()', function(data) {
        $form.submit();
    });
 });
/*代码样式*/
layui.use('code', function(){ 
layui.code({
elem: 'pre' 
,encode: true 
,title: '115CMS.COM'
,about: false
});
});
/*验证码*/
layui.use('form',function(){
  var form = layui.form
  ,jq = layui.jquery;
     jq('#sendRegCode').click(function() {
    var obj = $(this);
    var options = {
        seconds: 60
        , type: 'REG'
    };
     var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); 
     var mail = $("#usermail").val();
  　　if(mail == ""){ 
  　　　layer.msg('邮箱必填');
  　　　　return false;
  　　}else if(!reg.test(mail)){ 
 　　layer.msg('邮箱格式不对');
 　　　　return false;
 　　}
 　　loading = layer.load(0, {
         shade: [0.2, '#000']
    });
    jq.getJSON('/index.php/api/mail/email.html?mail='+mail, function(data) {
        if (data.code == 200) {
            layer.close(loading);
            layer.msg(data.msg, {
            icon: 1,
            time: 1000
        }, function() {
             countDown(60, obj);
        });
    } 
  });
 });
});
function countDown(seconds, obj) {
    if (seconds > 1) {
        seconds--;
        $(obj).attr('disabled', true).html(seconds + "秒");//禁用按钮
        setTimeout(function () {
            countDown(seconds, obj);
        }, 1000);
    } else {
        $(obj).attr('disabled', false).html("获取验证码");//启用按钮
    }
}

/*手机菜单*/
jQuery(document).ready(function ($) {
var modal = document.getElementById('myModal');
var btn = document.getElementById("myBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
    modal.style.display = "block";
}
span.onclick = function() {
    modal.style.display = "none";
}
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
});